package com.lcy.web;

import com.jfinal.config.*;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.template.Engine;
import com.lcy.web.controller.WebController;

/**
 * Created by loucunyin on 2017/1/11 0011.
 * 配置文件
 */
public class MyConfig extends JFinalConfig {
    @Override
    public void configConstant(Constants me) {
        me.setDevMode(true);
    }

    @Override
    public void configRoute(Routes me) {
        me.add("/", WebController.class);
    }

    @Override
    public void configEngine(Engine me) {

    }

    @Override
    public void configPlugin(Plugins me) {

        // 获取配置参数
        String url = Const.getDbUrl();
        String user = Const.getDbUser();
        String password = Const.getDbPassword();

        // 初始化数据库连接池插件
        C3p0Plugin c3p0Plugin = new C3p0Plugin(url, user, password);
        me.add(c3p0Plugin);

        ActiveRecordPlugin aPlugin = new ActiveRecordPlugin(c3p0Plugin);
        me.add(aPlugin);

        aPlugin.setDialect(new MysqlDialect());
        aPlugin.setShowSql(true);
    }

    @Override
    public void configInterceptor(Interceptors me) {

    }

    @Override
    public void configHandler(Handlers me) {

    }
}
